package com.tang.nacos.config;

/**
 * @Author tanglingyu
 * @Date: 2021/04/06/ 15:18
 * @Description
 */

import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * 普通数据库数据源
 *
 */
@Configuration
public class DataSourceConfig {


  // 主数据源配置 ds1数据源
  @Primary
  @Bean(name = "ds1DataSourceProperties")
  @ConfigurationProperties(prefix = "spring.datasource.ds1")
  public DataSourceProperties ds1DataSourceProperties() {
    return new DataSourceProperties();
  }

  // 主数据源 ds1数据源
  @Primary
  @Bean(name = "ds1DataSource")
  public DataSource ds1DataSource(@Qualifier("ds1DataSourceProperties") DataSourceProperties dataSourceProperties) {
    return dataSourceProperties.initializeDataSourceBuilder().build();
  }

}
